
/*==========================================================================
	Command:	wpp_toggle
	Purpose: 	Togles Trust
==========================================================================*/
concommand.Add("wpp_toggle",function(Player,_,Args)
	local Key,Uid = unpack(Args)
	
	if ( Uid == "global" ) then
		local Bool = !Player:WPP_HasGlobal(Key)
		hook.Call("WPP_SetGlobal",GAMEMODE,Player,Key,Bool)
	end
	
	local Target = player.GetByUniqueID( Uid )
	if ( Target ) then
		local Bool = !Player:WPP_HasTrust(Target,Key)
		hook.Call("WPP_SetTrust",GAMEMODE,Player,Target,Key,Bool)
	end
	
end)

/*==========================================================================
	Name:		GetBuddyActions
	Purpose: 	Get actions that are enabled for buddys (limited/unlimited)
===========================================================================*/
local function GetBuddyActions(Limit)
	Actions = {
		"Touch",
		"Grab",
		"Tool",
		"Use",
	}
	
	if (Limit == false) then
		table.insert(Actions,"Duplicate")
		table.insert(Actions,"Remove")
		table.insert(Actions,"CPPI")
	end
	
	if ( GetConVarNumber("wpp_anti_damage") >= 1 ) then table.insert(Actions,"Damage") end
	if ( GetConVarNumber("wpp_anti_noclip") >= 1 ) then table.insert(Actions,"Noclip") end
	if ( GetConVarNumber("wpp_anti_colide") >= 1 ) then table.insert(Actions,"Collision") end
	
	return Actions
end

/*==========================================================================
	Command:	wpp_buddy
	Purpose: 	Togles Trust
==========================================================================*/
concommand.Add("wpp_buddy",function(Player,_,Args)
	local Limit,Bool,Uid = unpack(Args)
	
	Limit = tobool(Limit)
	Bool = tobool(Bool)
	
	local List = GetBuddyActions(Limit)
	
	if ( Uid == "global" ) then
		for _,Key in pairs( List ) do
			hook.Call("WPP_SetGlobal",GAMEMODE,Player,Key,Bool)
		end
	end
	
	local Target = player.GetByUniqueID( Uid )
	if ( Target ) then
		for _,Key in pairs( List ) do
			hook.Call("WPP_SetTrust",GAMEMODE,Player,Target,Key,Bool)
		end
	end
	
end)

/*==========================================================================
	Command:	wpp_share
	Purpose: 	Shares Somthing
==========================================================================*/
concommand.Add("wpp_share",function(Player,_,Args)
	local E = Player:GetEyeTrace().Entity
	if ( !E ) or ( !E:IsValid() ) or ( !E:WPP_IsOwner(Player) ) then
		Player:PrintMessage( HUD_PRINTNOTIFY, "Please look at a prop you own.")
	end
	
	local Key,Bool = unpack(Args)
	
	E:WPP_SetShare(Key,tobool(Bool))
end)

/*==========================================================================
	Command:	wpp_share
	Purpose: 	Shares Somthing
==========================================================================*/
concommand.Add("wpp_cleanup",function(Player,_,Args)
	Player:PrintMessage( HUD_PRINTNOTIFY, "Cleaning up all your props.")
	
	for _,Entity in pairs ( ents.GetAll() ) do		
		if ( Entity:WPP_IsOwned() ) and ( Entity:WPP_IsOwner(Player) ) then
			Entity:Remove()
		end
	end
end)

/*==========================================================================
	Command:	wpp_share
	Purpose: 	Shares Somthing
==========================================================================*/
concommand.Add("wpp_clean_player",function(Player,_,Args)
	local Ply = player.GetByUniqueID(Args[1])
	
	if ( !Ply ) or ( !Player:IsAdmin() ) then return end
	if ( Ply:IsSuperAdmin() ) and ( !Player:IsSuperAdmin() ) then return end
	
	PrintMessage( HUD_PRINTNOTIFY, Player:Nick() .. " is cleaned up all props owned by " .. Ply:Nick() .. ".")
	
	for _,Entity in pairs ( ents.GetAll() ) do		
		if ( Entity:WPP_IsOwned() ) and ( Entity:WPP_IsOwner(Ply) ) then
			Entity:Remove()
		end
	end
end)

